package com.fengze.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fengze.business.vo.SupplierLibrarySelectVO;
import com.fengze.business.vo.SupplierLibraryVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fengze.common.annotation.Log;
import com.fengze.common.core.controller.BaseController;
import com.fengze.common.core.domain.AjaxResult;
import com.fengze.common.enums.BusinessType;
import com.fengze.business.domain.SupplierLibrary;
import com.fengze.business.service.ISupplierLibraryService;
import com.fengze.common.utils.poi.ExcelUtil;
import com.fengze.common.core.page.TableDataInfo;

/**
 * 供应商库Controller
 * 
 * @author lug
 * @date 2024-01-31
 */
@RestController
@RequestMapping("/counterpart/supplierlibrary")
public class SupplierLibraryController extends BaseController
{
    @Autowired
    private ISupplierLibraryService supplierLibraryService;

    /**
     * 查询供应商库列表
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplierLibrary supplierLibrary)
    {
        startPage();
//        List<SupplierLibrary> list = supplierLibraryService.selectSupplierLibraryList(supplierLibrary);
        List<SupplierLibraryVO> list = supplierLibraryService.selectSupplierLibraryVOList(supplierLibrary);
        return getDataTable(list);
    }


    @GetMapping("/listselect")
    public TableDataInfo listSelect(SupplierLibrary supplierLibrary)
    {
        startPage();
//        List<SupplierLibrary> list = supplierLibraryService.selectSupplierLibraryList(supplierLibrary);
        List<SupplierLibrarySelectVO> list = supplierLibraryService.selectSelectVOList(supplierLibrary);
        return getDataTable(list);
    }

    /**
     * 导出供应商库列表
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:export')")
    @Log(title = "供应商库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplierLibrary supplierLibrary)
    {
        List<SupplierLibrary> list = supplierLibraryService.selectSupplierLibraryList(supplierLibrary);
        ExcelUtil<SupplierLibrary> util = new ExcelUtil<SupplierLibrary>(SupplierLibrary.class);
        util.exportExcel(response, list, "供应商库数据");
    }

    /**
     * 获取供应商库详细信息
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(supplierLibraryService.selectSupplierLibraryVOById(id));
    }

    /**
     * 新增供应商库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:add')")
    @Log(title = "供应商库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplierLibrary supplierLibrary)
    {
        return toAjax(supplierLibraryService.insertSupplierLibrary(supplierLibrary));
    }

    /**
     * 修改供应商库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:edit')")
    @Log(title = "供应商库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplierLibrary supplierLibrary)
    {
        return toAjax(supplierLibraryService.updateSupplierLibrary(supplierLibrary));
    }

    /**
     * 删除供应商库
     */
    @PreAuthorize("@ss.hasPermi('counterpart:supplierlibrary:remove')")
    @Log(title = "供应商库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supplierLibraryService.deleteSupplierLibraryByIds(ids));
    }
}
